﻿@{
    var photoId = UrlData[0].AsInt();

    var db = Database.Open("PhotoGallery");

    var photo = db.QuerySingle("SELECT * FROM Photos WHERE Id = @0", photoId);
    if (photo == null) {
        Response.SetStatus(HttpStatusCode.NotFound);
        return;        
    }

    WebSecurity.RequireUser(photo.UserId);

    Page.Title = "Remove Photo - " + photo.FileTitle;

    if (IsPost) {
        //Remove all tags associated with this image
        db.Execute("DELETE FROM Photos_Tags WHERE Photos_Id = @0", photoId);
        //Remove all comments associated with this image
        db.Execute("DELETE FROM Comments WHERE PhotoId = @0", photoId);
        //Delete image
        db.Execute("DELETE FROM Photos WHERE Id = @0", photoId);
        Response.Redirect(Href("~/Gallery/View",photo.GalleryId));
    }
}

<div class="sidebar">
    <h1>@photo.FileTitle</h1>
    <h2 class="confirm-removal">Confirm Removal</h2>
    <p class="message error"> 
        Removing this photo will permanently delete the file from the photo gallery site 
        and you will lose all associated data (description, tags, and comments). You may 
        want to download the <a href="@Href("~/Photo/Full", photoId)" title="Download: @(photo.FileTitle + photo.FileExtension)">full size photo</a> before continuing. 
    </p>

    <form method="post" action="">
        <p class="form-actions">
            <input type="submit" value="Remove" title="Remove photo" />
            <a href="@Href("~/Photo/View", photoId)" title="Do not remove photo">Cancel</a>
        </p>
    </form>
</div>
<div class="main">
    <img src="@Href("~/Photo/Thumbnail", photo.Id, new { size="large" })" />
</div>